import { Component, OnInit, OnChanges, Input, Output, EventEmitter } from '@angular/core';


@Component({
  selector: 'app-stars',
  templateUrl: './stars.component.html',
  styleUrls: ['./stars.component.css']
})
export class StarsComponent implements OnInit, OnChanges {
  @Input()
  private rating: number = 0
  @Output()
  ratingChange: EventEmitter<number> = new EventEmitter()
  private stars: boolean[]
  @Input()
  private read: boolean = true;
  constructor() { }

  ngOnInit() {
    this.stars = []
    for (let i = 1; i <= 5; i++) {
      this.stars.push(i > this.rating)
    }
  }
  ngOnChanges(): void {
    this.stars = []
    for (let i = 1; i <= 5; i++) {
      this.stars.push(i > this.rating)
    }

  }
  clickStar(index: number) {
    if (!this.read) {
      this.rating = index + 1;
      this.ratingChange.emit(this.rating)
    }

  }
}
